'''
Company: TWL
Author: xue jian
Email: xuejian@kanzhun.com
Date: 2020-09-08 23:10:06
'''
'''
77. 组合
给定两个整数 n 和 k，返回 1 ... n 中所有可能的 k 个数的组合。

示例:

输入: n = 4, k = 2
输出:
[
  [2,4],
  [3,4],
  [2,3],
  [1,2],
  [1,3],
  [1,4],
]


tips: 这个就按二进制想，选或者不选。用递归做很容易，代码如下
'''
from typing import List
class Solution:
    def combine(self, n: int, k: int) -> List[List[int]]:
        import copy
        ans = []
        tmp = []
        def recurse(cur, n, k):
            if len(tmp)+n+1-cur<k:
                return
            if len(tmp) == k:
                # print(tmp)
                ttmp = copy.copy(tmp)
                ans.append(ttmp)
                return
            if cur == n+1:
                return
            tmp.append(cur)
            recurse(cur+1, n, k)
            tmp.pop()
            recurse(cur+1, n, k)
        recurse(1, n, k)
        return ans
if __name__ == "__main__":
    solusion = Solution()
    print(solusion.combine(4, 2))